package mdt;

import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Map;

import utils.BigFile;

import db.DataSourceFactory;
import db.DbUtil;
import db.MDTMySQLRowMapper;
import db.TransRunner;

public class GetEclipseCode {

	public static void main(String[] args) throws Exception {
		BigFile bf = new BigFile("VendorProductId.txt");
		PrintWriter pw = new PrintWriter(new FileOutputStream("VendorPIDToPID.tsv"));
		for(String line:bf){
			String vid = line.split("\t")[0];
			String pid = getProductIDByVendorProductID(vid);
			pw.println(line+"\t"+pid);
		}
		pw.close();
	}
	
	private static String getProductIDByVendorProductID(String vid) throws SQLException{
		String sql = "select ProductID from product where VendorProductID ="+DbUtil.escSql(vid);
        TransRunner runner = new TransRunner(DataSourceFactory.getDataSource("localhost","mdt","ChinacaT","ChinacaT"), new MDTMySQLRowMapper());
		Map row = runner.queryForMap(sql);
		if(row==null || row.size()==0)return "";
		return (String)row.get("ProductID");
	}

}
